<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/common/taglibs.jspf" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>流程设计</title>
    <meta name="decorator" content="list"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div  class="layui-col-md12">
            <grid:grid id="actModelList" url="${appPath}/act/deal/ajaxList" pageId="SYS:actModelList">
                <grid:column label="id"  name="id"  key="true" hidden="true" />
                <grid:column label="modelId"  name="modelId" hidden="true" />
                <grid:column label="流程ID"  name="workflowId" />
                <grid:column label="名称"  name="name"  query="true" condition="like" width="100"/>
                <grid:column label="业务"  name="businessName"  query="true" condition="like" width="100"/>
                <grid:column label="是否部署"  name="status" dict="whether"  />
                <grid:column label="机构"  name="orgId" redis="organizationCache" query="true" condition="like"   />
                <grid:column label="部门"  name="email" />
                <grid:column label="创建时间"  name="createDate"  />
                <grid:column label="sys.common.opt"  name="opt" formatter="button" width="500"/>
                <grid:button groupname="opt" id="btnEdit" title="编辑" onclick="modelInfo(row.id)" outclass="btn-primary" />
                <grid:button groupname="opt" id="btnDesign" title="设计流程图" onclick="designFlow(row.modelId)" outclass="btn-primary" />
                <grid:button groupname="opt" id="btnNodeSet" title="节点设置" onclick="flowNodeSet(row.modelId)" outclass="btn-primary" />
                <grid:button groupname="opt" id="btnShowFlow" title="查看流程图" onclick="showFlowImg(row.modelId)" outclass="btn-primary" />
                <grid:button groupname="opt" id="btnDeploy" title="部署" onclick="deploy(row.modelId,'部署')" outclass="btn-primary" exp="row.status==0" />
                <grid:button groupname="opt" id="btnUpgrade" title="升级版本" onclick="deploy(row.modelId,'升级')" outclass="btn-primary"  exp="row.status==1"/>
                <grid:button groupname="opt" id="btnDelete" title="删除" onclick="delModel(row.id)" outclass="btn btn-xs btn-danger"  exp="row.status==0"/>
                <grid:toolbar title="新增" onclick="modelInfo()" icon="icon-add"/>
                <grid:toolbar  function="search" />
                <grid:toolbar  function="reset" icon="icon-reload"  />
            </grid:grid>
        </div>
    </div>
</div>
<script>

    /**
     * 新增/编辑模型
     * @param id 扩展模型id
     */
    function modelInfo(id) {
        var url = "${appPath}/act/model/info";
        var titile ="新增模型";
        if(id !=""){
            url = "${appPath}/act/model/info?id="+id;
            titile ="编辑模型";
        }
        //弹框层
        layer.open({
            scrollbar: false,
            type: 2,
            title : [titile , true],
            area: ['30%', '450px'], //宽高
            content: [url,'no'],
            shadeClose : true,
        });
    }

    /**
     * 设计流程图
     * @param modelId 模型id
     */
    function designFlow(modelId) {
        var url="${appPath}/statics/plugins/process/modeler.html?modelId="+modelId;
        //弹框层
        layer.open({
            scrollbar: false,
            type: 2,
            title : ["流程图设计" , true],
            area: ['90%', '90%'], //宽高
            content: [url,'no'],
            shadeClose : false,
        });
    }

    /**
     * 保存模型提示框
     */
    function saveModelAlert(msg) {
        toast(msg);
    }

    /**
     * 流程节点设置
     * @param modelId 模型id
     */
    function flowNodeSet(modelId) {
        var url="${appPath}/act/model/flowTree?modelId="+modelId;
        //弹框层
        layer.open({
            scrollbar: false,
            type: 2,
            title : ["流程节点设置" , true],
            area:  ['800px', '500px'], //宽高
            content: [url,'no'],
            shadeClose : false,
        });
    }

    /**
     * 查看流程图片
     */
    function showFlowImg(modelId) {
        var url="${appPath}/act/model/showFlowImg?modelId="+modelId+"&r="+new Date().getTime();
        var html ="<img src ='"+url+"'/>";
        //弹框层
        layer.open({
            type: 1,
            area: ['70%', '70%'], //宽高
            content: html,
            title:['查看流程图',true],
            shadeClose: true, //开启遮罩关闭
        });
    }

    /**
     * 删除
     * @param id
     */
    function delModel(id) {
        var url ="${appPath}/act/model/del";
        confirm("确定删除该流程模型吗?",function () {
            $.post(url,"id="+id,function (result) {
                if(result.code == '0'){
                    toast(result.msg);
                    $("#table-list tr[name=model_"+id+"]").remove();
                }else {
                    alertMsg(result.msg);
                }
            });
        })
    }

    /**
     * 部署和升级版本
     * @param modelId
     */
    function deploy(modelId,title) {
        var url ="${appPath}/act/model/deploy";
        confirm("确定部署该流程模型吗?",function () {
            $.post(url,"modelId="+modelId,function (result) {
                if(result.code == '0'){
                    toast(title+":"+result.msg);
                    $("#search-from").submit();
                }else {
                    alertMsg(title+":"+result.msg);
                }
            });
        })
    }
</script>
</body>


</html>